package com.balabala.gym_user.controller.app;

import com.balabala.gym_user.pojo.entity.UserVipCard;
import com.balabala.gym_user.service.UserVipCardService;
import com.balabala.gym_user.service.VipCardService;
import com.balabala.result.Result;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author 何涛
 * @Date: 2023/05/01/ 17:33
 * @description 用户会员卡相关接口
 */
@RestController
@RequestMapping("/app/userVipCard")
@Api(tags = "用户会员卡前台相关接口")
@Slf4j
@CrossOrigin
public class UserVipCardAppController {
    @Autowired
    UserVipCardService userVipCardService;
    @Autowired
    VipCardService vipCardService;



    @PostMapping("addUserVipCard")
    @ApiOperation("添加用户会员卡信息")
    public Result addUserCardInfo()
    {
        return Result.ok();
    }

    @ApiOperation("查看用户会员卡信息")
    @GetMapping("getUserVipCards/{userId}")
    public Result getUserVipCards(@PathVariable Long userId)
    {
        log.info("查询用户会员卡");
        List<Long> vipCardIds = userVipCardService.list(new LambdaUpdateWrapper<UserVipCard>().eq(UserVipCard::getUserId, userId)).stream().map(userVipCard -> userVipCard.getVipCardId()).collect(Collectors.toList());

        return Result.ok(vipCardService.listByIds(vipCardIds));
    }

}
